﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace DtpAdmin
{
    static class Program
    {
        enum TestStatus { Unknown, OK, NoAccessToDB, InsufficientAccessLevel, InsufficientRights };
        /// <summary>
        /// Главная точка входа для приложения.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Database.InitDBengine();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            TestStatus rsltStatus = TestStatus.OK;

            if (!Database.TestConnection()) { rsltStatus = TestStatus.NoAccessToDB; }
            if (rsltStatus == TestStatus.OK)
            {
                if (!Database.TestDBAccess()) { rsltStatus = TestStatus.InsufficientAccessLevel; }
                if (rsltStatus == TestStatus.OK)
                {
                    if (!Database.TestSrvRole("sysadmin"))
                    {
                        rsltStatus = TestStatus.InsufficientRights;
                    }

                }
            }

            String sErrorMsg = String.Empty;
            switch (rsltStatus)
            {
                case TestStatus.OK:
                    Application.Run(new MainForm());
                    break;
                case TestStatus.NoAccessToDB:
                    sErrorMsg = "No access to database server";
                    break;
                case TestStatus.InsufficientAccessLevel:
                    sErrorMsg = "No access to database.";
                    break;
                case TestStatus.InsufficientRights:
                    sErrorMsg = "You have not specific database role";
                    break;
                case TestStatus.Unknown:
                    sErrorMsg = "Unknown error";
                    break;
            }

            if (rsltStatus != TestStatus.OK)
            {
                MessageBox.Show(sErrorMsg, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
    }
}
